*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Table C2
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************



cd "~/Dropbox/ReclassificationRisk/"
use database_individual_level.dta, replace 

 do Restat_Final_Table3_USIC.do
 do Restat_Final_Table4_EnrolleeLevel.do

 
****** HETEROGENEITY BY QUANTILES OF SIZE AND STATE

*********************************************************************************
*PERCENTILES OF SIZE

bys customer_number: egen max_numpeople =  max(numpeople) 
xtile quantiles_size = max_numpeople, nquantiles(10)
tab quantiles_size, gen(quantiles_size_dum)
forvalues i=1/10{
gen Rbysize_`i' = quantiles_size_dum`i'*mean_pred_riskscore_rp
}
reghdfe mean_premium Rbysize_* prob_leaving* yeardum* if sample==1, absorb(mbr_sys_id) cluster(customer_number year)
*********************************************************************************

 
*********************************************************************************
*HETEROGENEITY BY STATE 
gen state=0
replace state = 1  if minor_market=="ARKANSAS MINOR"
replace state = 2 if minor_market=="CENTRAL TEXAS MINOR" | minor_market=="DALLAS MINOR" | minor_market=="HOUSTON MINOR"  | minor_market=="NORTH TEXAS MINOR" | minor_market=="SOUTH TEXAS MINOR" 
replace state = 3 if minor_market=="EAST PENNSYLVANIA MINOR" | minor_market=="PENNSYLVANIA MINOR" | minor_market=="WEST PENNSYLVANIA MINOR"
replace state = 4 if minor_market=="ILLINOIS MINOR" | minor_market=="RV ILLINOIS MINOR" | minor_market=="SOUTHERN IL MINOR" 
replace state = 5  if minor_market=="KANSAS CITY MO MINOR" | minor_market=="MISSOURI MINOR"
replace state = 6  if minor_market=="OKLAHOMA MINOR"
replace state = 7  if minor_market=="TENNESSEE MINOR"
replace state = 8 if minor_market=="WISCONSIN MINOR"
replace state = 9  if minor_market=="WYOMING MINOR"
replace state = 10 if minor_market=="DELAWARE MINOR"

drop if state==0
tab(state), gen(statedum)

forvalues i=1/10 {
gen risk_int_rp`i' = statedum`i' *mean_pred_riskscore_rp
}

reghdfe mean_premium risk_int_rp* prob_leaving* yeardum* if sample==1, absorb(mbr_sys_id) cluster(customer_number year)
**********************************************************************************


**********************************************************************************
** HETEROGENEITY BY STAYERS 
cap drop industry_code
cap drop total_ind
cap drop sum_stayers
cap drop sum_all 
cap drop ratio_stayers 
gen industry_code =  substr(sic_cd, 1, 2)
gen total_ind = exjoiners_201314no2012 + exquitters_201213no2014 + exstayers_20121314no2015 + newjoiners2013_stayers2015 + newjoiners2014 + newstayers_allyears + everyone_onlyoneyear_aux + nocathegory
bys industry_code year: egen sum_stayers = sum(newstayers_allyears) 
bys industry_code year: egen sum_all = sum(total_ind) 
gen ratio_stayers = sum_stayers/ sum_all

xtile ratio_stayers_quant = ratio_stayers, nquantiles(10)
tab ratio_stayers_quant, gen(ratio_stayers_quant_dum)
forvalues i=1/10{
gen Rbyind_`i' = ratio_stayers_quant_dum`i'*mean_pred_riskscore_rp
}
reghdfe mean_premium Rbyind_* prob_leaving* yeardum* if sample==1, absorb(mbr_sys_id) cluster(customer_number year)

***********************************************************************************


**********************************************************************************
** NEW ACCOUNTS  

reghdfe mean_premium mean_pred_riskscore_rp prob_leaving yeardum* if sample==1 & newjoiners2013_stayers2015==1, absorb(mbr_sys_id) cluster(customer_number year)
reghdfe mean_premium mean_pred_riskscore_rp prob_leaving* yeardum* if sample==1 & newjoiners2013_stayers2015==1, absorb(mbr_sys_id) cluster(customer_number year)
reghdfe  mean_premium mean_pred_riskscore_rp prob_leaving marketdum* yeardum* if sample==1 & newjoiners2013_stayers2015==1,  noabsorb vce(cluster customer_number year)
reghdfe  mean_premium mean_pred_riskscore_rp prob_leaving* marketdum* yeardum* if sample==1 & newjoiners2013_stayers2015==1,  noabsorb vce(cluster customer_number year)

***********************************************************************************

*exit

**********************************************************************************
** REGRESSION AT THE FIRM LEVEL TO SEE PROJECTION OF CLAIMS ON COSTS 

reghdfe  mean_paid_current mean_pred_riskscore_rp                      if sample==1 ,  noabsorb vce(cluster customer_number year)
reghdfe  mean_paid_current mean_pred_riskscore_rp  marketdum*          if sample==1 ,  noabsorb vce(cluster customer_number year)
reghdfe  mean_paid_current mean_pred_riskscore_rp  marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)


*exit 


**********************************************************************************
** REGRESSION CORRECTING ABOUT MEASUREMENT ERROR  (OUR OWN RISK SCORE) 

reghdfe mean_premium mean_ORS_riskscore  yeardum* if sample==1 , absorb(mbr_sys_id) cluster(customer_number year)
reghdfe mean_premium mean_ORS_riskscore prob_leaving yeardum* if sample==1 , absorb(mbr_sys_id) cluster(customer_number year)
reghdfe mean_premium mean_ORS_riskscore prob_leaving* yeardum* if sample==1 , absorb(mbr_sys_id) cluster(customer_number year)
reghdfe  mean_premium mean_ORS_riskscore  marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)
reghdfe  mean_premium mean_ORS_riskscore prob_leaving marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)
reghdfe  mean_premium mean_ORS_riskscore prob_leaving* marketdum* yeardum* if sample==1 ,  noabsorb vce(cluster customer_number year)

exit 


